package com.dogkr.server.web;

import java.util.Date;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.ResultPath;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.dogkr.common.ServerAction;
import com.dogkr.server.entity.HostServerDate;
import com.dogkr.server.service.ServerDateService;
import com.sean.common.utils.DateUtils;


@ParentPackage(value = "login-default")
@Namespace(value = "/sevdate")
@ResultPath("/WEB-INF/jsps")
// 页面文件空间
@Results({
	
})
public class ServerDateAction extends ServerAction {

	private static final long serialVersionUID = 1L;

	private Date date;
	
	@Autowired
	private ServerDateService serverDateService;
	
	@Action(value="host")
	public void selectHostServerDate() {
		if(id == null) {
			id = this.getLoginUser().getHost().getId();
		}
		if(date == null) {
			date = new Date();
		}
		Date beginDate = DateUtils.getDateByString(DateUtils.getStartMonthDate(date));
		Date endDate = DateUtils.getDateByString(DateUtils.getEndMonthDate(date));
		List<HostServerDate> list = serverDateService.selectByHost(id, beginDate, endDate);
		outJson(list);
	}
	
	@Action(value="close")
	public void setClose() {
		serverDateService.saveCloseDate(this.getLoginUser().getHost().getId(), date);
		outJson(res);
	}
	
	@Action(value="open")
	public void setOpen() {
		serverDateService.saveOpenDate(this.getLoginUser().getHost().getId(), date);
		outJson(res);
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
}
